//
//  TabBarView.m
//  OCweibo
//
//  Created by 郑兆远 on 15/12/21.
//  Copyright © 2015年 zzy. All rights reserved.
//

#import "TabBarView.h"

@implementation TabBarView

- (instancetype)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
//    NSLog(@"%@",NSStringFromCGRect(self.frame));

    self.backgroundColor = [UIColor blueColor];
  return self;
}

- (UIButton *)composeBtn {
    if (!_composeBtn) {
        _composeBtn.adjustsImageWhenHighlighted = NO;
        _composeBtn = [[UIButton alloc]init];
        [_composeBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"]
                     forState:UIControlStateNormal];
        [_composeBtn
         setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"]
         forState:UIControlStateHighlighted];
        [_composeBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"]
                               forState:UIControlStateNormal];
        [_composeBtn
         setBackgroundImage:[UIImage
                             imageNamed:@"tabbar_compose_button_highlighted"]
         forState:UIControlStateHighlighted];
        [_composeBtn sizeToFit];
//        NSLog(@"======================");
        [self addSubview:_composeBtn];
//        NSLog(@"++++++++++++++++++++++++");
    }
  return _composeBtn;
}

- (void)layoutSubviews {
  [super layoutSubviews];
//    NSLog(@"%@",NSStringFromCGRect(self.bounds));
  CGFloat w = self.bounds.size.width / 5;
  CGFloat h = self.bounds.size.height;
  CGRect rect = CGRectMake(0, 0, w, h);
  CGFloat index = 0;
  //便利所有的子视图
    
  for (UIButton *button in self.subviews) {
      if ([NSStringFromClass([button class]) isEqualToString:@"UITabBarButton"]) {
//          NSLog(@"--------%f",index);
          button.frame = CGRectOffset(rect, w * index , 0);
//          NSLog(@"2222222%@",NSStringFromCGRect(button.frame));
          index += (index == 1 ? 2 : 1);
      }
  }
    _composeBtn.frame = CGRectOffset(rect, 2 * w, 0);
}




@end
